<?php  
$pPageIsPublic = false;
include '../_common.php';
	
$_SESSION["m1"]	= "restaurant";
$_SESSION["m2"] = 'restaurant-list';
$objName="Categoria"; $objUrl="restaurant"; $objTitle="Categoria";

$pTitle  = "Nuevo {$objTitle}";
$pButton = 'Guardar';
$action  = 'add';
$id 	 = intval($_REQUEST['id']);
$pid 	 = intval($_REQUEST['pid']);
$seo	 = NULL;


$objLoad = new Categoria();
$objLoad ->setUid($id);
if ($objLoad ->load()) {
	$pTitle  = "Editar {$objTitle}";
	$pButton = 'Actualizar';
	$action  = 'edit';
	$pid = $objLoad ->restaurant ->id;
	
	/*if ($_GET['action']=='del') {
		$objLoad ->removeFile('img');
		$message = "Imagen ha sido eliminado.";
	}*/
}

if (isset($_POST['submit'])) {
	$objLoad ->setAuto($_POST);
	$objLoad ->restaurant ->id = $_POST['pid'];
	//$objLoad ->uploadFile('ifile', 'img');
	if ($_POST['action'] == 'edit') {
		$objLoad ->getConnection();
		$objLoad ->setUid($id);
		$objLoad ->update();
		Tzn::redirect("categoria-add.php?id={$objLoad ->id}", "{$objTitle} ha sido actualizada.");
	} elseif ($_POST['action'] == 'add') {
		$objLoad ->add();
		Tzn::redirect("categoria-add.php?pid={$objLoad ->restaurant ->id}&id={$objLoad ->id}", "{$objTitle} ha sido registrada.");
	}
}
?>
<?php include("header.php"); ?>
<?php
$tabs 	= array('menu' => 1);
$selTab = $tabs[$_REQUEST['tab']] ? $tabs[$_REQUEST['tab']] : 0;
?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();
	$('#content-tabs').tabs({
		disabled :[<?= !$objLoad ->isLoaded() ? "1" : "" ?>],
		active  : <?= $selTab ?>
	});	
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=categoria" > Atras </a></li>
	<li class="noborder" >
		<a class="add" href="<?= $_SERVER["PHP_SELF"] ?>?pid=<?= $pid?>" > Agregar una <?= $objTitle ?> </a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> <?= $objLoad ->isLoaded() ? "- <span class=\"mark\" >\"{$objLoad ->titulo}\"</span>" : "" ?> </h2>
<div id="content-tabs">
		<ul>
			<li><a href="#fragment-1" ><span>Info Categor&iacute;a</span></a></li>
			<li><a href="#fragment-2"><span>Men&uacute;s</span></a></li>
		</ul>
		<div id="fragment-1" >  
			<form action="" method="post" name = "frmMain" id = "frmMain"  enctype="multipart/form-data" >
			<fieldset><legend> Informaci&oacute;n General  </legend>
				<table cellpadding="0" cellspacing="0" class="table-form"  >
					<tr>
						<th>Restaurant: </th>
						<td><?php
						 $tmp = new Restaurant();
						 $tmp ->addOrder('titulo ASC');
						Generic::gSelect($tmp, '', ($objLoad ->isLoaded() ? $objLoad ->restaurant ->id : $pid) , '--- seleccionar un restaurant ---', '', 'class="required"', 'pid');    ?></td>
					</tr>
					<tr>
						<th>T&iacute;tulo: </th>
								<td><?php $objLoad ->qText('titulo', '', 'width:548px', 'class="required"');?></td>
							</tr>
						<!-- tr>
							<th>Subt&iacute;tulo: </th>
								<td><?php $objLoad ->qText('subtitulo', '', 'width:548px', 'class=""');?></td>
							</tr-->
							<tr>
								<th>Descripcion:</th>
								<td><?php $objLoad ->qTextArea('descripcion', '', 'width:548px;height:60px;', ''); ?></td>
							</tr>
							<!-- tr>
								<th>Imagen: </th>
								<td><?php $objLoad ->pFile('ifile', "{$_SERVER['PHP_SELF']}?id={$objLoad ->id}&action=del", 'img', 'img') ?></td>
							</tr-->
							<tr>
								<th>Estado: </th>
								<td><?php $objLoad ->arrayToSelect($objLoad ->_arrStatus, 'estado', $objLoad ->estado, false, 'width:100px', '');?></td>
							</tr>
						</table>
				</fieldset>
				<div style="margin-top:10px">
					<input type="hidden" name="id" value="<?php echo $id; ?>" />
					<input type="hidden" name="action" value="<?php echo $action; ?>" />
						<input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancelar" onClick="window.location.href='<?= $objUrl ?>-add.php?id=<?= $pid?>&tab=categoria'" />
			            </div>
			</form>
		</div>
		<div id="fragment-2">
			<fieldset><legend> Listado de men&uacute;s <?= $objLoad ->isLoaded() ? "- {$objLoad ->titulo}" : "" ?>  </legend>
				<?php 
					Common::hFrmFilterAdmin('Menu', 'Men&uacute;', 'menu', "pid={$objLoad ->id}");
					$objChild  = new Menu();
					$objChild ->loadItems("#orderId ASC", "#estado like '". $chkstatus ."%' AND #categoriaId='". intval($objLoad ->id) ."'");
					echo "<div id='wrap-list'>" . Common::hSimpleGridV2('Menu', 'Men&uacute;', 'menu', $objChild, true,
							array(
								'description' => true,
								/*'navs' 		  => array (
									0 => array (
										'title' 	=> 'Men&uacute;s',
										'count'     => 'gMenuCount',
										'objName' 	=> 'Menu'
									)
								)*/
								'navs' => array (
										0 => array (
											'custom' => '<p class="sub-nav">&raquo; Precio: <strong>S/.@precio</strong></p>',
										)
								)									
							)
							, false) . '</div>';
				?>
			</fieldset>
		</div>
</div>		
		
</div>
<?php include("footer.php"); ?>